#include <iostream>
#include "thread_pool.h"
#include <stdio.h>

class Task1 : public lakes::TaskAbstract
{
public:

     Task1(int num) {
        _num = num;
     }

    ~Task1() {
      
    }

    void Task() override {   
        printf("%d : %d\n", std::this_thread::get_id(), _num);
        std::chrono::seconds dura(1);
        std::this_thread::sleep_for(dura);
    }

private:
    int _num;
};


int main() {
    lakes::ThreadPool pool(2, 7);
    /*
        或者 
        lakes::ThreadPool pool(2, 7, false);
        // ...
        pool.start();
        在创建时就不会启用线程池.
    */

    pool.setHook(1000, [](lakes::ThreadPool* pool) {
        printf("now statubusyThread: %d liveThread: %d queueNum : %d\n", 
            pool->getBusyThreadNumber(), pool->getLiveThreadNumber(), pool->getTaskQueueNumber());
    });

    for (int i = 0; i < 100; i++) {
        pool.addTask(new Task1(i));
    }
    
    std::this_thread::sleep_for(std::chrono::seconds(30));
    pool.finish(); // 手动停止, 也可以不调用, 析构函数会自动调用.
    return 0;
}


